﻿using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;

namespace UntanglerApp
{
    public class AssemblyPack
    {
        public string Name { get; set; }
        public string Root { get; set; }
        public IList<string> Assemblies { get; set; }

        public XElement ToXElement()
        {
            return new XElement("AssemblyPack",
                new XAttribute("Name", Name),
                new XAttribute("Root", Name),
                new XElement("Assemblies",
                    (from n in Assemblies select new XElement("Assembly", n)).ToList())
                );
        }

        public static AssemblyPack FromXElement(XElement xml)
        {
            return new AssemblyPack
                        {
                            Name = xml.Attribute("Name").Value,
                            Root = xml.Attribute("Root").Value,
                            Assemblies = (from element in xml.Element("Assemblies").Elements("Assembly")
                                            select element.Value).ToList()
                        };
        }
    }
}
